import 'dart:math';

import 'package:flutter/cupertino.dart';

import '../models/refine_user_info.model.dart';

class RefineUserInfoViewModel with ChangeNotifier {
  final RefineUserInfoModel _refineUserInfoModel;

  RefineUserInfoViewModel()
      : _refineUserInfoModel = RefineUserInfoModel(
    sex: Sex.male,
    name: _generateName(),
    avatar: 'assets/images/avatar-male.png',
    birthDate: DateTime.now(),
  );

  static String _generateName() {
    List<String> adjectives = [
      '一鸣惊人的',
      '激情四溢的',
      '纯真的',
      '英俊潇洒的',
      '温文尔雅的',
      '活力十足的',
      '机智聪明的',
      '心地善良的',
      '勇敢无畏的',
      '聪慧过人的',
      '温柔体贴的',
      '阳光灿烂的',
      '风度翩翩的',
      '俏皮可爱的',
      '神秘莫测的',
      '深情款款的',
      '机智幽默的',
      '才子佳人的',
      '调皮捣蛋的',
      '豪爽直率的',
      '儒雅文人的',
      '独立自主的',
      '优雅自信的'
    ];
    List<String> names = [
      '熙豪',
      '翔畅',
      '宸钰',
      '睿杰',
      '子轩',
      '博文',
      '雅婷',
      '雨桐',
      '子涵',
      '思远',
      '宇轩',
      '怡萱',
      '泽宇',
      '心怡',
      '雨琳',
      '梦瑶',
      '思怡',
      '钰彤',
      '子墨',
      '浩然',
      '若涵',
      '子琪',
      '晨曦',
      '乐思',
      '梓萱',
      '诗语',
      '辰铭'
    ];

    Random random = Random();
    String adjective = adjectives[random.nextInt(adjectives.length)];
    String name = names[random.nextInt(names.length)];
    return '$adjective$name';
  }

  Map<String, dynamic> get refineUserInfoForm {
    return {
      'name': _refineUserInfoModel.name,
      'avatar': _refineUserInfoModel.avatar,
      'sex': _refineUserInfoModel.sex,
      'birthDate': _refineUserInfoModel.birthDate,
    };
  }

  void setSex(Sex sex){
    _refineUserInfoModel.sex = sex;
    notifyListeners();
  }

  void setName(String name){
    _refineUserInfoModel.name = name;
    notifyListeners();
  }

  void setAvatar(String avatar){
    _refineUserInfoModel.avatar = avatar;
    notifyListeners();
  }

  void setBirthDate(DateTime birthDate){
    _refineUserInfoModel.birthDate = birthDate;
    notifyListeners();
  }

  void generateName() {
    _refineUserInfoModel.name = _generateName();
    notifyListeners();
  }

  static Future<void> submit() async {
    // 提交逻辑
  }
}
